package xing.design.pattern.behavioral.Memento.sample2;

/**
 * @author xing
 * @date 2023/2/10 1:46:01
 */
public class Main {
    public static void main(String[] args) {
        // init
        BaseOriginator originator = new BaseOriginator();
        originator.setInfo("origin");

        // create snapshot
        Memento memento = originator.createSnapshot();

        // ------ usage 1 ------
        // modify info
        originator.setInfo("hah");
        // restore 1
        memento.restore();
        System.out.println("restore info: " + originator.getInfo());
        System.out.println("---");

        // ------ usage 2 ------
        // modify info again.
        originator.setInfo("hah");
        // restore 2
        boolean restore = memento.restore(originator);
        System.out.println("is restore: " + restore);
        System.out.println("restore info: " + originator.getInfo());
    }
}
